package com.example.controller;

import cn.hutool.core.util.ObjectUtil;
import com.example.common.Result;
import com.example.entity.AdminInfo;
import com.example.entity.TeacherInfo;
import com.example.service.AdminIfoService;
import com.example.service.TeacherInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/teacherInfo")
public class TeacherInfoController {

    @Resource
    private TeacherInfoService teacherInfoService;
    @Autowired
    private RestTemplateAutoConfiguration restTemplateAutoConfiguration;

    @PutMapping
    public Result update(@RequestBody TeacherInfo teacherInfo){
        teacherInfoService.update(teacherInfo);
        return Result.success();
    }
    @GetMapping
    public Result findAll(){
        List<TeacherInfo> list = teacherInfoService.findAll();
        return Result.success(list);
    }
    @PostMapping
    public Result add(@RequestBody TeacherInfo teacherInfo){
        teacherInfoService.add(teacherInfo);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable(value = "id") Long id){
        teacherInfoService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageInfo<TeacherInfo> info = teacherInfoService.findPage(pageNum,pageSize);
        return Result.success(info);
    }

    @GetMapping("/page/{name}")
    public Result findPageName(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @PathVariable String name){
        PageInfo<TeacherInfo> info = teacherInfoService.findPageName(pageNum,pageSize,name);
        return Result.success(info);
    }
}
